package com.spring.application;

import com.spring.entity.Book;
import com.spring.entity.Coffie;
import com.spring.factory.MyFactoryBean;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringApplication_4 {

    //Bean使用静态工厂和实例工厂进行创建
    @Test
    public void getBeanFactory(){
        ApplicationContext context = new ClassPathXmlApplicationContext("springIOC-conf-4.xml");
        Coffie coffie = context.getBean("coffie",Coffie.class);
        System.out.println(coffie);
    }

    //使用FactoryBean进行创建
    @Test
    public void getFactoryBean() throws Exception {
        ApplicationContext context = new ClassPathXmlApplicationContext("springIOC-conf-4.xml");
        Object book = context.getBean("book");
        Object book2 = context.getBean("book");
        System.out.println(book == book2) ;
    }
}
